var _util = require('util/util.js')
var vue = require('./../common/vue')
const { toHandlerKey } = require('vue');
const _other_service = require('service/other-service');

//创建vue对象
var seller_content = new vue({
    el: "#seller_content",
    //定义数据
    data: {
        sellerArray: [
            {
                username: "hsj",
                password: "123",
                phone: "123",
                // "picturesrc": "<image src="/image/user_picture/1.jpg">",
                email: "123@qq.com",
                available: 1,
                shopnum: 3,
                picturesrc: "<image src=\"/image/user_picture/1.jpg\">"
            },
            {
                username: "hsjasda",
                password: "123",
                phone: "123",
                // "picturesrc": "<image src="/image/user_picture/1.jpg">",
                email: "123@qq.com",
                available: 1,
                shopnum: 3
            },
            {
                username: "hsj111",
                password: "123",
                phone: "123",
                // "picturesrc": "<image src="/image/user_picture/1.jpg">",
                email: "123@qq.com",
                available: 1,
                shopnum: 3,
                picturesrc: "<image src=\"/image/user_picture/1.jpg\">"
            }
        ],
        //搜索框关键字
        search_keywords : "",
        /*
            修改启用状态
            edit_sellername: 当前操作的用户名
            available: 是否启用
         */
        edit_sellername : "",
        available: "",
        /*
            分页查询参数 1!5!
         */
        pagesize: 5,
        pageid: 1,
    },
    methods: {
        //查询所有的用户(分页)
        search: function () {
            console.log(this.search_keywords)
            _other_service.getAllSellerBy(seller_content.search_keywords,
                function (res) {
                    data.sellerArray = res;
                },
                function (err) {
                    console.log(err);
                })
        },
        //设置卖家账号是否禁用
        setavailable : function(index){
            console.log("点击了账号禁用");
            this.edit_sellername = this.sellerArray[index].username;
            this.available = this.sellerArray[index].available;
            _other_service.modifySellerStatus(
                seller_content.edit_sellername,
                seller_content.available,
                function(res) {
                    alert("修改卖家状态成功");
                },
                function(err) {
                    alert("修改卖家状态失败");
                }
            )
        },
        deleteSellerAccount: function (index){
            this.edit_sellername = this.sellerArray[index].username;
            _other_service.deleteSellerAccount(
                seller_content.edit_sellername,
                function(res) {
                    alert("卖家删除成功");
                },
                function(err) {
                    alert("卖家删除失败");
                }
            )
        },
        resetSearchInfo : function(){
            this.search_keywords = "请输入卖家名";
        }
    },
    //初始化vue对象，渲染数据
    created: function () {
        _other_service.getAllSeller(seller_content.pagesize, seller_content.pageid,
            function (res) {
                seller_content.data.sellerArray = res.data;
            },
            function (res) {
                console.log("渲染数据错误")
            }
        );
    },
});
